package JUnit;

import static org.junit.Assert.*;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.security.PublicKey;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import connection.FileClient;
import crypt.CryptRSA;
/**
 * @version 1.0
 * @author Jonas Untiet
 *
 */
public class CryptRSATest {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testCryptRSA() throws IOException{
		ByteArrayOutputStream test = new ByteArrayOutputStream();
		DataOutputStream out = new DataOutputStream(test);
		out.write( 'H' ); out.write( 'A' ); out.write( 'L' ); out.write( 'L' ); out.write( 'O' );
		out.close();
		byte[] data = test.toByteArray();
		
		CryptRSA rsa = CryptRSA.getInstance();
		PublicKey pubKey = rsa.getPublicKey();
		byte[] verschluesselt = rsa.encrypt(data, pubKey);
		byte[] entschluesselt = rsa.decrypt(verschluesselt);
		assertArrayEquals(data, entschluesselt);
		assertArrayEquals("Hallo",data,entschluesselt);
	
	}

}
